package cn.hxth.cloud.consumer.controller;

import cn.hxth.cloud.api.domain.OrderInfo;
import cn.hxth.cloud.service.service.OrderService;
import org.apache.shiro.SecurityUtils;
import org.springframework.format.datetime.DateFormatter;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/pages/order/")
public class OrderController {
    @InitBinder
    public void intDate(WebDataBinder dataBinder){
        dataBinder.addCustomFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));
        dataBinder.addCustomFormatter(new DateFormatter("yyyy-MM-dd"));
    }
    @Resource
    private OrderService orderService ;
    @PostMapping("insertOrder")
    public Boolean insertOrder( OrderInfo orderInfo){
       String mid = SecurityUtils.getSubject().getPrincipal().toString();
       //String mid = (String) SecurityUtils.getSubject().getSession().getAttribute("mid");
   //   String mid = (String) request.getSession().getAttribute("mid");
try{
        System.out.println(mid+"======================");
        return  this.orderService.insertOrder(orderInfo,mid) ;

    }catch (Exception e){
    e.printStackTrace();
    return  false ;
    }
    }
    @PutMapping("updateStatus")
    public  Boolean updateStatus(OrderInfo orderInfo){
        return  this.orderService.updateStatus(orderInfo) ;
    }

}
